#!/bin/bash -i

# Stop on errors
set -e

cd "$(dirname "$0")/.."

rm -rf dist
mkdir -p dist/web
cp -r public/* dist/web

# Quit all background tasks when script exits
trap "kill 0" EXIT

# Run tsc once as rollup expects those files
npm exec -- tsc || true

npm exec -- serve -p 5010 dist/web &
npm exec -- tsc --watch &
npm exec -- rollup -c --watch
